package ochart.elements
{
	import flash.events.Event;
	import flash.geom.Point;
	
	import ochart.core.ChartObject;
	import ochart.utils.ArrayUtil;
	
	public class DataElement extends ChartObject implements IDataElement
	{
		public static const CLASS_NAME:String = "DataElement";
		
		override public function get className():String
		{
			return CLASS_NAME;
		}
		
		public static const ALIAS:String = "dataElement";
		
		override public function get alias():String
		{
			return ALIAS;
		}
		
		public var isAddToDataElementsArray:Boolean = true;
		
		public var value:* = null;
		
		private var defaultValue:Object = 
		{
			
		}
		
		private var _propertiesArray:Array = null;
		
		override public function get propertiesArray():Array
		{
			if(_propertiesArray)
			{
				return _propertiesArray;
			}
			
			_propertiesArray = super.propertiesArray;
			for(var name:String in defaultValue)
			{
				if(!ArrayUtil.containsValue(_propertiesArray, name))
				{
					_propertiesArray.push(name);
				}
			}
			return _propertiesArray;
		}
		
		public function DataElement()
		{
			super();
			
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
		}
		
		override protected function onAddedToStage(event:Event):void
		{
			super.onAddedToStage(event);
			
			if(isAddToDataElementsArray)
			{
				chart.dataElementsArray.push(this);
			}
		}
		
		protected function onRemovedFromStage(event:Event):void
		{
			ArrayUtil.removeValue(chart.dataElementsArray, this);
		}
		
		override public function getDefaultValue(name:String):*
		{
			return (defaultValue[name] === undefined) ? super.getDefaultValue(name) : defaultValue[name];
		}
		
		public function evaluateSpace(point:Point):Number
		{
			return -1;
		}
	}
}